package gui;

import physics.Forcer;

import java.io.Serializable;
import java.lang.reflect.Constructor;
import java.util.Hashtable;


public class ForcerEditorManager implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private static ForcerEditorManager fme = new ForcerEditorManager();
	public static ForcerEditorManager get() {
		return fme;
	}
	
	private Hashtable<Class<? extends Forcer>,Constructor<? extends ForcerEditor<?>>> table;
	private ForcerEditorManager() {
		table = new Hashtable<Class<? extends Forcer>,Constructor<? extends ForcerEditor<?>>>();
	}
	public ForcerEditor<?> getEditor(Forcer f) {
		try {
			return table.get(f.getClass()).newInstance(f);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
	public void registerForcerEditor(Class<? extends Forcer> forcer,Class<? extends ForcerEditor<?>> menu) {
		try {
			table.put(forcer, menu.getConstructor(forcer));
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
